var oFCKeditorOptions = {
    BasePath: '../fckeditor/',
    Config: {
        BaseHref: 'http://172.18.4.127:8080/itnetwork/',
        SkinPath: '../editor/skins/office2003/',//../../fckeditor/editor/skins/office2003/
        CustomConfigurationsPath: '../fckconfig.js',
        ProcessHTMLEntities: true,
        ProcessNumericEntities: false
    },
    AllowQueryStringDebu: false,
    ToolbarSet: 'Default'
};

Ext.form.FCKeditor = function(config){
    this.config     = config;
    Ext.form.FCKeditor.superclass.constructor.call(this, config);
    this.MyisLoaded = false;
    this.MyValue    = '';
    this.fckInstance= undefined; // to avoid using FCKAPI, this is a reference to instance created on FCKeditor_OnComplete
};

Ext.extend(Ext.form.FCKeditor, Ext.form.TextArea, {
    onRender : function(ct, position){
    	//alert("fckeditor 渲染..");
        if(!this.el){
            this.defaultAutoCreate = {
                tag: "textarea",
                style:"width:100px;height:60px;",
                autocomplete: "off"
            };
        }
        Ext.form.TextArea.superclass.onRender.call(this, ct, position);
        //Hide textarea to stop flashing up before FCKEditor renders.
        this.hideMode = "visibility"; // set hideMode to visibility, to retain height.
        this.hidden = true; // hide textarea
        if(this.grow){
            this.textSizeEl = Ext.DomHelper.append(document.body, {
                tag: "pre", cls: "x-form-grow-sizer"
            });
            if(this.preventScrollbars){
                this.el.setStyle("overflow", "hidden");
            }
            this.el.setHeight(this.growMin);
        }
        setTimeout("loadFCKeditor('"+this.name+"',"+ this.config.height +");",100);
    },      //onrender....................
    setValue : function(value){
        this.MyValue = value;
        //alert("ncontent.setValue()后this.MyValue的值为="+this.MyValue);
        if (this.MyisLoaded){
        	//alert("Myisloaded ="+this.MyisLoaded+",设置fckeditor的Data="+value+"  紧接调用父类的serValue方法");
        	//Ext.form.TextArea.superclass.setRawValue.apply(this,[value]);
        	//alert("调用FCKeditorSetValue(this.name,value)。。。其中value为"+value);
          FCKeditorSetValue(this.name,value); 
          alert("调用FCKeditorSetValue(this.name,value)之后，调用getValue方法，取得的值为="+this.getValue());
         // this.serRawValue(value);
        }
        Ext.form.TextArea.superclass.setValue.apply(this,[value]);
       // alert("this.MyValue = "+this.MyisLoaded);
    }/*,
    serRawValue:function(value){
    	   this.MyValue = value;
	        if (this.MyisLoaded){
	        	alert("fckeditor set Rawvalue  Rawvalue is ="+value);
	          FCKeditorSetValue(this.name,value);          
	        }
	        Ext.form.TextArea.superclass.setRawValue.apply(this,[value]);
    }*/,
    getValue : function(){
        if (this.MyisLoaded){
            value = FCKeditorGetValue(this.name);
           //  alert("fckeditor get  value="+value);
            Ext.form.TextArea.superclass.setValue.apply(this,[value]);
            return Ext.form.TextArea.superclass.getValue.call(this);
        	//return value;
        } else {
        	//alert("getValue MysiLoaded = "+this.MyisLoaded+"但返回this.MyValue的值 为="+this.MyValue);
            return this.MyValue;
        }
    },
    getRawValue : function(){
        if (this.MyisLoaded){
            value=FCKeditorGetValue(this.name);
           // alert("fckeditor get  Rawvalue="+value);
            Ext.form.TextArea.superclass.setRawValue.apply(this,[value]);
            return Ext.form.TextArea.superclass.getRawValue.call(this);
           // return value;
        } else {
        //	alert("紧接getValue，调用getRawValue MysiLoaded = "+this.MyisLoaded+"但返回this.MyValue的值 为="+this.MyValue);
            return this.MyValue;
        }
    }
});
Ext.reg('fckeditor', Ext.form.FCKeditor); //别名

function loadFCKeditor(element, height){
    oFCKeditor  = new FCKeditor(element);
    oFCKeditor.Height = height;
    Ext.apply(oFCKeditor,oFCKeditorOptions)//把开始的json对象赋值给新创建的oFCKeditor的原形中
    oFCKeditor.ReplaceTextarea();
    //this.MyisLoaded=true;
}

function FCKeditor_OnComplete(editorInstance){
	//editorInstance.SwitchEditMode(); 
	//alert("FCKeditor_OnComplete Invode and set this.originalValue="+this.originalValue);
    Ext.getCmp(editorInstance.Name).MyisLoaded = true;
    Ext.getCmp(editorInstance.Name).fckInstance = editorInstance;
   // if(this.originalValue!="")
    	 Ext.getCmp(editorInstance.Name).fckInstance.SetData( Ext.getCmp(editorInstance.Name).MyValue);
}
function FCKeditorSetValue(name,value){
    if (name != undefined){
        var extCmp = Ext.getCmp(name);
        if (extCmp != undefined) {
            extCmp.fckInstance.SetData(value);
        }
    }
}
function FCKeditorGetValue(name){
    if (name != undefined){
        var data = '';
        var extCmp = Ext.getCmp(name);
        if (extCmp != undefined) {
            data = extCmp.fckInstance.GetData();
        }
        return data;
    }
}

